package com.kaishengit.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kaishengit.pojo.Provider;
import com.kaishengit.service.ProviderService;

@Controller
public class ProviderController {
	private ProviderService providerService;
	
	@RequestMapping("/providerList")
	public String findAll(Model model){
		List<Provider> providerList = providerService.findAll();
		model.addAttribute("providerList",providerList);
		return "provider_list";
	}
	@RequestMapping("/addProvider")
	public String addProvider(Provider provider){
		providerService.add(provider);
		return "redirect:/providerList";
	}
	@RequestMapping("/findByProviderId{id}")
	public @ResponseBody Provider findByProviderId(@PathVariable String id){
		Provider provider = providerService.findById(id);
		return provider;
	}
	@RequestMapping("/editProvider")
	public String editProvider(Provider provider){
		providerService.edit(provider);
		return "redirect:/providerList";
	}
	@RequestMapping("/delProvider{id}")
	public String del(@PathVariable String id){
		providerService.del(id);
		return "redirect:/providerList";
	}
	
	@Autowired
	public void setProviderService(ProviderService providerService) {
		this.providerService = providerService;
	}
	
}
